package com.baosight.sczx.zm.service;

import org.apache.log4j.Logger;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.soa.SoaManager;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.ed.util.CodesetBiz;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;

/**
 * 
 * <p>Title: ServiceZM01.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-7-16 下午01:35:18  严洪浩  Create
 *</pre>
 */
public class ServiceZM01 extends ServiceEPBase {
	@SuppressWarnings("unused")
	private static final Logger logger = Logger.getLogger(ServiceZM01.class);

	@SuppressWarnings("unused")
	private CodesetBiz codeBiz = (CodesetBiz) SpringApplicationContext.getBean("codesetBiz");

	/**
	 * 页面初始化，返回组织好的层级小代码
	 * 
	 * @param EiInfo
	 * @return EiInfo
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		return this.query(inInfo);
	}

	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM01</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-16下午01:35:26 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String bindingService = inInfo.getString("bindingService");
		if (bindingService != null && !"".equals(bindingService.trim())) {
			String[] tokens = bindingService.split("\\.");
			if (tokens.length >= 2) {

				inInfo.set(EiConstant.serviceName, tokens[0]);
				inInfo.set(EiConstant.methodName, tokens[1]);

				String initParam = inInfo.getString("initParam");
				if (initParam != null && !"".equals(initParam.trim())) {
					String[] params = initParam.split("\\|");
					for (int i = 0; i < params.length; i++) {
						String[] param = params[i].split("\\:");
						if (param.length >= 2) {
							StaticTools.setQueryParameters(inInfo, param[0], param[1], true);

						}
					}
				}
				inInfo.addBlock(EiConstant.resultBlock).set(EiConstant.isCountFlag, "true");
				inInfo = SoaManager.invoke(inInfo);
			}
		}

		return inInfo;
	}
}
